package com.itheima.Demo3charset;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

public class charsetDemo1
{
    //写程序编程编码和解码
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s1 = "中国";
        //编码
        byte[] bytes = s1.getBytes();//平台UTF-8编码 中文三个字节 110xxxxx 10xxxxxx 10xxxxxx
        byte[] bytes2 = s1.getBytes("GBK");//指定GBK编码 中文两个字节 1xxxxxxx xxxxxxxx
        System.out.println( bytes.length);
        System.out.println( bytes2.length);
        //解码
        String s2 = new String(bytes);//默认UTF-8解码
        String s3= new String(bytes2,"GBK");//指定GBK解码
    }
}
